package ar.arcraft.core;

import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

import utils.database.MySQL;

public class Arcraft {
	public static void executeCommandAsPlayer(Player player, String cmd){
		Server server = Bukkit.getServer();
		Boolean wasOp = player.isOp();
		try
		{
		    player.setOp(true);
		    server.dispatchCommand(player, cmd);
		}
		catch(Exception e)
		{
		    e.printStackTrace();
		}
		finally
		{
		    if(!wasOp){
		    	player.setOp(false);
		    }
		}
	}
	public static MySQL mysqlConnect(JavaPlugin plugin){
		String url = plugin.getConfig().getString("SQLOptions.url");
		String db = plugin.getConfig().getString("SQLOptions.db");
		String port = plugin.getConfig().getString("SQLOptions.port");
		String username = plugin.getConfig().getString("SQLOptions.username");
		String password = plugin.getConfig().getString("SQLOptions.password");
		MySQL mySQL = new MySQL(plugin, url, port, db, username, password);
		return mySQL;
	}
	
}